/**
 * @author Mario, Tran
 */

import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Paint;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.Timer;
/*
 * make buttons bigger and prettier
 * set's teacher's admin button to only be visible
 * if admin is log in.
 * also add in some comments as this class lacks them
 */

public class panel2 extends JPanel implements ActionListener{

	 blankButton Game;
	 blankButton vocab;
	 blankButton WPM;
	 blankButton LogOut;
	 sound selectSound;
	 public Timer time;
	 
	 public panel2()
	 {
		 //also uses gridbaglayout
		 //
	 Font font = new Font("Ubuntu Mono", Font.BOLD, 16);
	 
     selectSound = new sound();
     pointerIcon = new ImageIcon("selector.png");
     pointer = pointerIcon.getImage();
     //mouseover is used to triggered the sound effects
     //when mouse moves over choice selection
     mouseOver m = new mouseOver();
		 
	 this.setLayout(new GridBagLayout());
	 GridBagConstraints c = new GridBagConstraints();
	 Dimension d = new Dimension(190,30);
	 //Insets is to set a nice equal distance between
	 //each of the items on the gui
	 c.insets = new Insets(5,5,5,5);
	 c.gridx=0;
	 c.gridy=0;
     Game = new blankButton("Game");
     Game.setFont(font);
     Game.addMouseListener(m);
     Game.setPreferredSize(d);
     Game.setMinimumSize(d);
     add(Game,c);
     
     vocab = new blankButton("Vocabulary");
     vocab.setFont(font);
     vocab.addMouseListener(m);
     vocab.setPreferredSize(d);
     vocab.setMinimumSize(d);
     c.gridy=1;
     add(vocab,c);
     
     WPM = new blankButton("Speed Test");
     WPM.setFont(font);
     WPM.addMouseListener(m);
     WPM.setPreferredSize(d);
     WPM.setMinimumSize(d);
     c.gridy=2;
     add(WPM,c);
     
     LogOut = new blankButton("Log Out");
     LogOut.setFont(font);
     LogOut.addMouseListener(m);
     LogOut.setPreferredSize(d);
     LogOut.setMinimumSize(d);
     c.gridy=3;
     add(LogOut,c);
     
     time = new Timer(50,this);
     time.start();
	 }
	 
	 boolean peaked = false;
	 
	 public void selectorMotion(){
		 if(pointerX<208 && peaked==false){
			 pointerX+=2;
		 	if(pointerX==208)
		 		peaked=true;
		 }
		 
		 if(pointerX>190 && peaked==true){
			 pointerX-=2;
			if(pointerX==190)
				peaked=false;
		 }
		 
	 }
	 
	 
	
	public void actionPerformed(ActionEvent e){
		selectorMotion();
		repaint();
	}
	 ImageIcon pointerIcon;
	 Image pointer;
	 int pointerY = 250;
	 int pointerX = 190;
	 
	 
		public void paintComponent(Graphics g) {
			
			Graphics2D g2 = (Graphics2D) g;
			GradientPaint p;
			p = new GradientPaint(0, 50, Color.WHITE, 0, getHeight()*2,new Color(123,53,153));//variation of purple RGB

			Paint oldPaint = g2.getPaint();
			g2.setPaint(p);
			g2.fillRect(0, 0, 800, 600);
			g2.setPaint(oldPaint);
			g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
			g.drawImage(pointer, pointerX, pointerY, null);
		  }
		
		
		
		
		private class mouseOver implements MouseListener,MouseMotionListener{
			public void mouseEntered(MouseEvent e){
				selectSound.select();
				if(e.getComponent()==Game){
					pointerY= 250;
					repaint();
				}
				if(e.getComponent()==vocab){
					pointerY= 270;
					repaint();
				}
				if(e.getComponent()==WPM){
					pointerY= 290;
					repaint();
				}
				if(e.getComponent()==LogOut){
					pointerY= 310;
					repaint();
				}
			}

			@Override
			public void mouseClicked(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseExited(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseReleased(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void mouseDragged(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}

		

			@Override
			public void mouseMoved(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}

		}
}
